Socket
Socket
Sign inDemoInstall

retext-visit

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retext-visit

Retext node visitor


Version published
Weekly downloads
1
decreased by-94.12%
Maintainers
1
Weekly downloads
 
Created
Source

retext-visit Build Status Coverage Status

retext node visitor.

Installation

npm:

$ npm install retext-visit

Component.js:

$ component install wooorm/retext-visit

Bower:

$ bower install retext-visit

Duo:

var visit = require('wooorm/retext-visit');

Usage

var Retext = require('retext');
var visit = require('retext-visit');
var inspect = require('retext-inspect');

var retext = new Retext()
    .use(inspect)
    .use(visit);

/*
 * See each function signature below.
 */

API

TextOM.Parent#visit(callback)

retext.parse('A simple English sentence.', function (err, tree) {
    if (err) throw err;

    /* Visit every node in the first sentence. */
    tree.head.head.visit(function (node) {
        console.log(node);
    });
    /*
     * Logs:
     *
     * WordNode[1]
     * └─ TextNode: 'A'
     * TextNode: 'A'
     * WhiteSpaceNode[1]
     * └─ TextNode: ' '
     * TextNode: ' '
     * WordNode[1]
     * └─ TextNode: 'simple'
     * TextNode: 'simple'
     * WhiteSpaceNode[1]
     * └─ TextNode: ' '
     * TextNode: ' '
     * WordNode[1]
     * └─ TextNode: 'English'
     * TextNode: 'English'
     * WhiteSpaceNode[1]
     * └─ TextNode: ' '
     * TextNode: ' '
     * WordNode[1]
     * └─ TextNode: 'sentence'
     * TextNode: 'sentence'
     * PunctuationNode[1]
     * └─ TextNode: '.'
     * TextNode: '.'
     */
});

Invoke callback for every descendant of the operated on context.

Parameters:

  • callback (function(Node): boolean?): Visitor. Stops visiting when it returns false.

TextOM.Parent#visit(type, callback)

retext.parse('A simple English sentence.', function (err, tree) {
    if (err) throw err;

    /* Visit every word node. */
    tree.visit(tree.WORD_NODE, function (node) {
        console.log(node);
    });
    /*
     * WordNode[1]
     * └─ TextNode: 'A'
     * WordNode[1]
     * └─ TextNode: 'simple'
     * WordNode[1]
     * └─ TextNode: 'English'
     * WordNode[1]
     * └─ TextNode: 'sentence'
     */
});

Invoke callback for every descendant of the context of type.

Parameters:

  • type: Type of visited nodes.
  • callback (function(Node): boolean?): Visitor. Stops visiting when the return value is false.

Performance

On a MacBook Air.

             Visit every node
  7,806 op/s » A section
    670 op/s » An article

             Visit every word node
  6,249 op/s » A section
    521 op/s » An article

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 18 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc